package cn.toma.controller.others;

import cn.toma.common.exception.FfBootException;
import cn.toma.common.utils.web.HttpUtil;
import cn.toma.common.vo.FfBootConstant;
import cn.toma.config.web.utli.FfBootResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("article")
public class ArticleController
{

	@GetMapping
	@RequiresPermissions("article:view")
	public FfBootResponse queryArticle(String date) throws FfBootException
	{
		String param;
		String data;
		try {
			if (StringUtils.isNotBlank(date)) {
				param = "dev=1&date=" + date;
				data = HttpUtil.sendSSLPost(FfBootConstant.MRYW_DAY_URL, param);
			}
			else {
				param = "dev=1";
				data = HttpUtil.sendSSLPost(FfBootConstant.MRYW_TODAY_URL, param);
			}
			return new FfBootResponse().data(data);
		} catch (Exception e) {
			String message = "获取文章失败";
			log.error(message, e);
			throw new FfBootException(message);
		}
	}
}
